package com.cn.action;

import java.util.List;
import java.util.Set;

import com.cn.domain.Customer;
import com.cn.domain.Order;
import com.cn.service.CustomerService;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.ModelDriven;

public class CustomerAction extends ActionSupport implements ModelDriven<Customer> {

	private Customer customer = new Customer();
	private CustomerService customerService;
	@Override
	public Customer getModel() {
		// TODO Auto-generated method stub
		return customer;
	}
	public void setCustomerService(CustomerService customerService) {
		this.customerService = customerService;
	}
	//查询所有的用户
	public String findAllCustomer(){
	List<Customer> listcustomer	= customerService.findAllCustomer();
	ActionContext.getContext().getValueStack().set("listcustomer", listcustomer);
		return "listcustomer";
	}
	//删除用户
	public String deleteCustomer(){
	  customerService.deleteCustomer(customer.getCid());	
	return "deletcustomer";
	}
	
    //查询订单的方法
	public String getExitLoginUsername(){
		//得到session
	String _loginusername =	(String)ActionContext.getContext().getSession().get("exitcustomer");
	Customer cust = customerService.getExitLoginUsername(_loginusername);
	System.out.println(cust.getPassword());
	System.out.println(cust.getOrderset().size());
    Set<Order> orderset = cust.getOrderset();
	ActionContext.getContext().getValueStack().set("orderset",orderset);
	return "ordercustomerindex";
	}
}
